#!/bin/bash
set -e
set -x
MYDIR="${0%/*}"
cd "$MYDIR/.."
source "recipes/common.sh"


# RECIPE START file

# XXX: building file requires file
reset_mtime file file/configure
save_CFLAGS="$CFLAGS"
save_CPPFLAGS="$CPPFLAGS"
save_LDFLAGS="$LDFLAGS"
unset CFLAGS
unset LDFLAGS
mkdir -p build/file_native
cd build/file_native
../../file/configure \
	--host="$BUILD" \
	--build="$BUILD" \
	--disable-shared \
	--prefix="$build_prefix" \
	${AUTOCRAP_KLUDGE}

cd ../..
make_native_build build/file_native

export CFLAGS="$save_CFLAGS"
export CPPFLAGS="$save_CPPFLAGS"
export LDFLAGS="$save_LDFLAGS"

reset_mtime file file/configure
mkdir -p build/file
cd build/file
env PATH="$xtools${build_prefix}/bin:${PATH}" \
../../file/configure \
	${CONFIGURE_ARGS} \
	${AUTOCRAP_KLUDGE}

# XXX:
# - cross-compilation fails when building in parallel
# - a native version of file is necessary to compile magic db
env PATH="$stage/$build_prefix/bin:${PATH}" \
make -j1
env PATH="$stage/$build_prefix/bin:${PATH}" \
make -j1 install DESTDIR="$stage"
wipe_la_files "$stage"
cd ../..

# RECIPE END file
